<!DOCTYPE html>
<html lang="en">
<head>
    <title>公共平台 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- 样式文件的引入 -->
    <link href="commons/css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="commons/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="commons/themes/icon.css">
    <!-- jqueryUI JS文件的引入 -->
    <script type="text/javascript" src="commons/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="commons/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="commons/js/easyui-extends-validate.js"></script>
    <!-- jqueryUI国际化 -->
    <script type="text/javascript" src="commons/js/easyui-lang-zh_CN.js"></script>
    <!-- 开发使用的公用js方法 -->
    <script type="text/javascript" src="commons/js/common.js"></script>
    <!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
    <script type="text/javascript">var ctx = '/comm-dictionary-server';var actionExt = "action";var i18n = new Object();</script>
    <script src="commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'west',border:true" style="width:260px;">
        <div style="padding:0;border:1px solid #ddd;width: 240px;height: 14px;background-color: #f5f5f5;text-align: center;font-size: 12px;padding: 8px;">
            请 选 择 系 统
        </div>
        <input id="selSysCodeCombobox" class="easyui-combobox" data-options="
        panelHeight:'auto',
        valueField: 'id',
        textField: 'text',
        width:'255px',
        animate:true,
        onSelect: function(rec){
            clickMenuSys(rec);
        }">
        <div style="padding:0;border:1px solid #ddd;width: 240px;height: 14px;background-color: #f5f5f5;text-align: center;font-size: 12px;padding: 8px;">
            数 据 字 典 树
        </div>
        <ul id="dictTree"></ul>
    </div>
    <div data-options="region:'center',border:false"  style="margin-left: 6px;">
        <div class="easyui-layout" data-options="fit:true,border:false" >
            <div data-options="region:'north',border:false" style="padding-bottom: 4px;height: 46px;">
                <div class="easyui-panel" data-options="fit:true,border:true" >
                    <div  class="queryContent" style="height: 32px;">
                        <form name="searchForm" id="searchForm" method="post" action="" style="display: none; ">
                            <table class="queryTable" >
                                <tbody>
                                <tr>
                                    <th>字典项名称</th>
                                    <td width="10%">
                                        <input class="easyui-validatebox" type="text" name="name" maxlength="20" style="width:120px" id="dicName"></input>
                                        <input type="hidden" name="pId" value="1" id="pIdDiv">
                                        <input type="hidden" name="sysCode" value="common" id="sysCodeDiv">
                                    </td>
                                    <td align="right" width="10%"><a href="javascript:void(0);" class="easyui-linkbutton" id="search" plain="true">查询</a>
                                        <a href="javascript:void(0);" class="easyui-linkbutton" id="resetSearch" plain="true">清空</a>
                                        <a href="javascript:initData();" class="easyui-linkbutton" plain="true">初始化数据</a>
                                        </td>
                                </tr>
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <div data-options="region:'center',border:false">
                    <table id="listTable" class="easyui-datagrid"
                           data-options="singleSelect:false,toolbar:'#tb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
					pagination:true,remoteSort:true,multiSort:true,striped:true,pageList:[20,30,40,50]"}>
                    <thead>
                    <tr>
                        <th data-options="field:'id',checkbox:true"></th>
                        <th data-options="field:'name',width:100,sortable:true,formatter: function(value,row,index){
								return '<a href=javascript:void(0);  onclick=openDataDialog(paramObj,\''+row.id+'\',freshTree) >'+value+'</a>';
							},title:'字典名称'"></th>
                        <th data-options="field:'value',width:100,title:'值'"></th>
                        <th data-options="field:'pName',width:100,title:'上级节点'"></th>
                        <th data-options="field:'remark',width:150,title:'字典项说明'"></th>
                        <th data-options="field:'updaterName',width:70,title:'更新人'"></th>
                        <th data-options="field:'updateTime',sortable:true,width:100,title:'更新时间'" align="center"></th>
                    </tr>
                    </thead>
                </table>
                <div id="tb" style="display: none;">
                    <div>
                        <a href="javascript:void(0);" onclick="openDataDialog(paramObj,undefined,freshTree);" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
                        <a href="javascript:void(0);" onclick="updateData(paramObj,freshTree);" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
                        <a href="javascript:void(0);" onclick="deleteData(paramObj,freshTree);" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id='firstLevelDialog'/>
</body>
<script type="text/javascript">
    //初始化表格对应的js对象
    var paramObj;
    var parentId = 'root';
    var parentName;
    var childId;
    var sysCode;
    $(function() {
        //初始化表格对象数据
        paramObj = new initParams(
            {
                paramObjName : 'paramObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
                tableId:'listTable',
                addDataFormId:'addDataForm',
                showDialogId:'firstLevelDialog',
                searchID:'search',
                resetSearchID:'resetSearch',
                searchFormID:'searchForm',
                updateUrl:"/comm-dictionary-server/dic-input.html?id=",
                deleteUrl:'/comm-dictionary-server/dictionaryManage/delete',
                addDialogWidth:700,
                addDialogHeight:280,
                ctx:'/comm-dictionary-server',
                addDialogTitle:'数据字典信息'
            });
        //初始化查询
        init(paramObj);
        $('#listTable').datagrid("options").url='/comm-dictionary-server/dictionaryManage/findPageDictionaryByPId';
        queryData(paramObj);
        //树形图初始化
        $('#dictTree').tree({
            onClick: function(node){
                clickMenu(node);
            },
            url:'/comm-dictionary-server/dictionaryManage/dictTreeList',
            queryParams:{pId:'root',sysCode:'common'},
            method:'get',
            animate:false,
            lines:true
        });
        //下拉选项初始化
        $.getJSON('/comm-dictionary-server/dictionaryManage/listSys?parentValue=sys_code',function(jsonData){
            $('#selSysCodeCombobox').combobox({
                data:jsonData.data,
                valueField:'value',
                textField:'name'
            });
        });

    });
    //点击树形图枝点或叶子节点触发
    function clickMenu(node) {
        var name = $('#dicName').val();
        $('#pIdDiv').val(node.id);
        parentName = node.text;
        if(sysCode != undefined) {
        	$('#sysCodeDiv').val(sysCode);
        }
        queryData(paramObj);
    }

    // //在选择系统下拉框选择系统后,查询字典结果展示在树形图中
    function clickMenuSys(node) {
        sysCode = node.value;
        $('#dictTree').tree("options").queryParams={pId:'root','sysCode':sysCode} ;
        $('#dictTree').tree("reload");
        $('#sysCodeDiv').val(sysCode);
        queryData(paramObj);
    }

    //刷新树
    function freshTree() {
        $('#dictTree').tree("reload");
    }
    
    function initData(){
    	$.ajax({
			type: "get",
			url:  '/comm-dictionary-server/dictionary/initDictionaryData',
			async : false,
			success: function(data,res){
				if(data.success == true){
					$.messager.alert('提示','初始化数据成功！','info');
				} else {
					$.messager.alert('提示','初始化数据失败：' + data.errorMsg,'error');
				}
			},
			error: function(res){
				$.messager.alert('提示',i18n.requestError,'error');
			}
		});
    }

</script>
</html>